package org.game.db.proxy.bean;

import org.cfg.BuildCfg;
import org.cfg.cache.BuildCfgCache;
import org.game.constant.BuildingConstant;
import org.game.db.bean.Building;

import com.sojoys.artifact.build.data.base.BasePojoProxy;
import org.game.db.bean.City;
import org.game.db.bean.Player;
import org.game.db.bean.Role;
import org.game.db.cache.CityCache;
import org.game.db.cache.RoleCache;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : DengYing
 * @CreateDate : 2017年11月30日 下午2:26:01
 * @Description ：建筑扩展
 */
public class BuildingProxy extends BasePojoProxy<BuildingProxy, Building>{

	public BuildCfg getCfg(){
		return BuildCfgCache.me().getById(t.getCid());
	}

	public BuildCfg getNextLevelCfg(){
		BuildCfg cfg = getCfg();
        return BuildCfgCache.me().getByBuildIdLevel(cfg.getBuildId(),cfg.getLevel()+1);
    }

    public int getBuildId(){
		return getCfg().getBuildId();
	}

	/**
	 * 获取能够进行城市约会的看板娘列表
	 * @return
	 */
	public List<Integer> getCanCityDatingRoleList(){
		return (List<Integer>) t.getRoleId().stream()
				.map(id-> RoleCache.me().getById((Long) id))
				.filter(role->!((Role)role).getRoleProxy().isCriticalPoint())
				.map(role->((Role)role).getCid())
				.collect(Collectors.toList());
	}

	/**
	 * 仅在建筑恢复空闲状态的时候使用
	 */
	public void clear(){
    	t.setState(BuildingConstant.BUIDING_STATE_FREE);
    	t.setFinishTime(null);
    	t.setNextRewardTime(null);
    	t.getRoleId().clear();
    	t.getReward().clear();
    	t.getEventLogs().clear();
    	t.update();
	}

	public City getCity(Player player){
		return CityCache.me().getByCidPlayerId(getCfg().getCityId(),player.getId());
	}
}
